package com.gjr.eduservice.controller;

import com.gjr.commonutils.Result;
import com.gjr.eduservice.entity.EduSubject;
import com.gjr.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author gjr
 * @since 2021-12-08
 */
@Api(description = "课程科目模块")
@CrossOrigin
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {
    @Autowired
    private EduSubjectService eduSubjectService;

    /**
     * 添加课程分类
     * 获取上传过来的文件，把文件内容读取出来
     *
     * @param file 文件对象
     * @return json
     */
    @ApiOperation(value = "添加课程分类")
    @PostMapping("/addSubject")
    public Result<?> addSubject(MultipartFile file) throws IOException {
        // 上传过来的excel 文件
        eduSubjectService.saveSubject(file, eduSubjectService);
        return Result.ok();
    }

    /**
     * 课程分类列表（树形结构）
     *
     * @return json
     */
    @ApiOperation(value = " 课程分类列表（树形结构）")
    @GetMapping("/getAllSubject")
    public Result<?> getAllSubject() {
        List<Map<String, Object>> list = eduSubjectService.getAllSubject();
        return Result.ok().data("list", list);
    }

}

